package com.easemob.chat;

import android.content.Context;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import com.easemob.EMCallBack;
import com.easemob.analytics.ActiveCollector;
import com.easemob.chat.core.f;
import com.easemob.chat.core.f.c;
import com.easemob.chat.core.k;
import com.easemob.debug.DebugHelper;
import com.easemob.util.EMLog;
import com.easemob.util.EMLog.ELogMode;

public class EMChat
{
  private static final String TAG = "EaseMob";
  private static EMChat instance = new EMChat();
  boolean appInited = false;
  private boolean autoLogin = true;
  private boolean initSingleProcess = true;
  private boolean sdkInited = false;
  private Context appContext = null;
  private String userName = null;
  private String password = null;
  private static final String PID_FILE = ".easemob.pid";

  public static EMChat getInstance()
  {
    return instance;
  }

  public void setDebugMode(boolean paramBoolean)
  {
    EMChatConfig.debugMode = paramBoolean;
    EMLog.debugMode = paramBoolean;
  }

  public void setLogMode(EMLog.ELogMode paramELogMode)
  {
    EMLog.setLogMode(paramELogMode);
  }

  public void setAutoLogin(boolean paramBoolean)
  {
    this.autoLogin = paramBoolean;
  }

  public void setAppInited()
  {
    this.appInited = true;
    EMChatManager.getInstance().onAppInited();
  }

  public void setInitSingleProcess(boolean paramBoolean)
  {
    this.initSingleProcess = paramBoolean;
  }

  public void uploadLog(EMCallBack paramEMCallBack)
  {
    DebugHelper.uploadLog(EMChatConfig.getInstance().getApplicationContext(), f.a().c().a, paramEMCallBack);
  }

  public void setUserName(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
      return;
    this.userName = paramString;
  }

  public void setPassword(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
      return;
    this.password = paramString;
  }

  public void init(Context paramContext)
  {
    if ((this.initSingleProcess) && (checkSDKInited(paramContext)))
    {
      Log.d("EaseMob", "skip init easemob since already inited");
      return;
    }
    EMLog.e("EaseMob", "easemob init in process:" + Process.myPid());
    this.appContext = paramContext.getApplicationContext();
    boolean bool = EMChatConfig.getInstance().loadConfig(this.appContext);
    if (!bool)
    {
      Log.e("EaseMob", "wrong configuration");
      throw new RuntimeException("Initialization failed! : wrong configuration");
    }
    InitSmackStaticCode.initStaticCode(paramContext);
    EMChatManager localEMChatManager = EMChatManager.getInstance().onInit();
    EMSessionManager localEMSessionManager = EMSessionManager.getInstance().onInit();
    String str1 = this.userName;
    EMLog.e("EaseMob", "passed userName : " + this.userName);
    if (str1 == null)
      str1 = localEMSessionManager.getLastLoginUser();
    ActiveCollector.sendActivePacket(this.appContext);
    EMLog.e("EaseMob", "is autoLogin : " + this.autoLogin);
    EMLog.e("EaseMob", "lastLoginUser : " + str1);
    if (this.autoLogin)
    {
      if (isLoggedIn())
      {
        String str2 = this.password;
        if (str2 == null)
          str2 = localEMSessionManager.getLastLoginPwd();
        localEMSessionManager.login(str1, str2, false, null);
      }
    }
    else if ((str1 != null) && (!str1.equals("")))
    {
      localEMChatManager.initDB(str1);
      localEMChatManager.loadDB();
    }
    EMLog.e("EaseMob", "HuanXin SDK is initialized with version : " + k.a().b());
    this.sdkInited = true;
  }

  public String getVersion()
  {
    return k.a().b();
  }

  public Context getAppContext()
  {
    return this.appContext;
  }

  public void setEnv(EMChatConfig.EMEnvMode paramEMEnvMode)
  {
    EMChatConfig.getInstance().setEnv(paramEMEnvMode);
  }

  public boolean isLoggedIn()
  {
    if ((!TextUtils.isEmpty(this.userName)) && (!TextUtils.isEmpty(this.password)))
      return true;
    EMSessionManager localEMSessionManager = EMSessionManager.getInstance();
    String str1 = localEMSessionManager.getLastLoginUser();
    String str2 = localEMSessionManager.getLastLoginPwd();
    return (str1 != null) && (str2 != null) && (!str1.equals("")) && (!str2.equals(""));
  }

  boolean isSDKInited()
  {
    return this.sdkInited;
  }

  private boolean checkSDKInited(Context paramContext)
  {
    return this.sdkInited;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.EMChat
 * JD-Core Version:    0.6.1
 */